package cn.wolfcode.luowowo.member.domain;


import cn.wolfcode.luowowo.common.domain.BaseDomain;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import java.util.Date;

@Setter
@Getter
@ToString
public class UserInfo extends BaseDomain {

    public static final int GENDER_SECRET = 0; //保密
    public static final int GENDER_MALE = 1;   //男
    public static final int GENDER_FEMALE = 2;  //女
    public static final int STATE_NORMAL = 0;  //正常
    public static final int STATE_DISABLE = 1;  //冻结

    private String nickname;  //昵称
    private String phone;  //手机
    private String email;  //邮箱
    private String password; //密码
    private  Long money;//蜂蜜
    private int gender = GENDER_SECRET; //性别
    private int level = 0;  //用户级别
    private String city ;  //所在城市
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday; //生日
    private String headImgUrl; //头像
    private String info;  //个性签名
    private int state = STATE_NORMAL; //状态
    private String favorId; //关联的攻略id，多个用,分开
    private Long[] favorIds;//收藏攻略id 1,2,3
    private Long fansnum;//粉丝数
    private Long idols;//关注数
    private String idolId;//关联关注用户的id
    private Long idolIds;

    //将得到的favorId转换成long类型数组
    public Long[] getFavorIds(){
        Long[] favorIds = null;
        if(StringUtils.hasLength(favorId)){
            String[] strs = favorId.split(",");
            favorIds = new Long[strs.length];
            for (int i = 0; i <strs.length ; i++) {
                favorIds[i] = Long.parseLong(strs[i]);
            }
        }
        return favorIds;
    }

    public Long[] getidolIds(){
        Long[] idolIds = null;
        if(StringUtils.hasLength(idolId)) {
            String[] str = idolId.split(",");
            idolIds = new Long[str.length];
            for (int i = 0; i < str.length; i++) {
                idolIds[i] = Long.parseLong(str[i]);
            }
        }
        return idolIds;
    }


    public Long getIdols(){
        if (this.getidolIds()==null) {
            return 0L;
        }
        return (long) this.getidolIds().length;
    }
}